package cn.edu.hunan.pm.common;

import java.util.HashMap;
import java.util.Map;



/**
 * 封装响应的结果
 * @author hb
 * @date 2024-06-20 09:18:12
 */
public class R {

    private Integer code;//业务状态码

    private Boolean flag;//标识结果的状态
    private String message;//状态的描述

    private Map<String,Object> data;//响应的结果
    public R( ) {

    }

    public R(Integer code, Boolean flag, String message) {
        this.code = code;
        this.flag = flag;
        this.message = message;
        this.data=new HashMap<>();
    }


    public static R error(){
        R r = new R();
        r.setFlag(false);
        return r;
    }

    public static R ok(){
        R ok = new R(200200, true, "ok");
        return ok;
    }

    public R code(Integer code){
        this.setCode(code);
        return this;
    }

    public R message(String message){
        this.setMessage(message);
        return this;
    }

    public R data(String key,Object value){
        this.data.put(key,value);
        return this;
    }



    public Integer getCode() {
        return code;
    }

    public void setCode(Integer code) {
        this.code = code;
    }

    public Boolean getFlag() {
        return flag;
    }

    public void setFlag(Boolean flag) {
        this.flag = flag;
    }

    public String getMessage() {
        return message;
    }

    public void setMessage(String message) {
        this.message = message;
    }

    public Map<String, Object> getData() {
        return data;
    }

    public void setData(Map<String, Object> data) {
        this.data = data;
    }
}
